﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoginLog.aspx.cs" Inherits="LoginLog" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>使用情况查询 </title>
    <link rel="stylesheet" type="text/css" href="../../css/theme.css" />
    <link rel="stylesheet" type="text/css" href="../../css/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/icon.css" />
    <script src="../../js/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../js/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../js/Json.js" type="text/javascript"></script>
    <script src="../../js/Common.js" type="text/javascript"></script>
    <script src="../../js/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    
    <style type="text/css">
        .ftitle
        {
            font-size: 14px;
            font-weight: bold;
            padding: 5px 0;
            margin-bottom: 10px;
            border-bottom: 1px solid #ccc;
        }
        .fitem
        {
            margin-bottom: 5px;
        }
        .fitem label
        {
            display: inline-block;
            width: 80px;
        }
        .searchBlock
        {
            padding-left: 20px;
        }
        .searchBlock span
        {
        }
        
        .searchTitle
        {
            padding-right: 2px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="container" style="width: 100%; padding: 5px">
        <div id="toolbar" style="text-align: left; padding-bottom: 10px">
             <a href="javascript:void(0)" class="easyui-linkbutton"  onclick="pageJs.search()">搜索</a>  
             <a href="javascript:void(0)" class="easyui-linkbutton"  onclick="pageJs.del()">删除</a>  
             <div style="padding-top:5px"> 
             <span class="searchTitle">菜单</span> <input style=" width:150px"  id="sMenu" />
                      <span class="searchTitle">访问日期</span> 
                      <input style="width: 120px" class="Wdate" type="text" id="startDate" onclick="WdatePicker({isShowClear:true,readOnly:true})" />
                      ~<input style="width: 120px" class="Wdate" type="text" id="endDate" onclick="WdatePicker({isShowClear:true,readOnly:true})" />
             </div>
        </div>
        <div id="divTable" style="text-align: left">
           <table border=0 cellpadding=0 cellspacing=0 >
            <tr>
                  <td valign=top>
                
                    <div id="divGrid" style="float:left;width:400px">
                    <table id="dg" title="菜单登录统计"  style="height:350px; width:380px"     
                             pagination="true"   autoRowHeight="false"
                             rownumbers="true" fitColumns="false" singleSelect="true">  
                         <thead>  
                             <tr>  
                                 <th field="FUNCTION_NAME" width="150">菜单名称</th>  
                                 <th field="LOGIN_COUNT" width="100">登录次数</th>  

                             </tr>  
                         </thead>  
                     </table>    
                    </div> 
                  </td>
           
                  <td valign=top>
                          <table id="dgDetail" title="菜单登录明细"  style="height:350px; width:380px"     class="easyui-datagrid"  
                             pagination="true"   autoRowHeight="false"
                             rownumbers="true" fitColumns="false" singleSelect="true">  
                         <thead>  
                             <tr>  
                                 <th field="LOGIN_USER_ID" width="100">用户代码 </th>  
                                 <th field="LOGIN_USER_NAME" width="120">用户名称</th>  
                                 <th field="LOGIN_DATE" width="150">登录时间</th> 
                                 <th field="LOGIN_IP" width="100">登录IP</th>   
                             </tr>  
                         </thead>  
                     </table>              
                  </td>
              </tr> 
              </table>
        </div>
    </div>
    </form>
    
    <script type="text/javascript">
        var pageJs = {
            url: "",
            resize: function (h, w) {
                $('#container').height(h).width(w - 10);
                var contentH = h - $("#toolbar").outerHeight() - 10;
                if (contentH < 120) contentH = 120;
                var gWidth = $(window).width() - 410 ;
                if (gWidth < 100) gWidth = 100;
                $("#dg").datagrid("resize", { height: contentH });
                $("#dgDetail").datagrid("resize", { height: contentH, width: gWidth });

            },

            del: function () {
                var row = $('#dg').datagrid('getSelected');
                if (row) {

                    $.messager.confirm('删除登录日志', '您确定要刪除选中菜单的登录日志吗?', function (r) {
                        if (r) {
                            $.post(pageJs.url + "?action=del", { FUNCTION_KEY: row.FUNCTION_KEY }, function (result) {
                                if (result.Success) {
                                    $('#dg').datagrid('reload');    // reload the user data
                                    BasicJs.showMessage("刪除成功！", true);
                                } else {
                                    if (result.Message) BasicJs.showMessage(result.Message);
                                }
                            }, 'json');
                        }
                    });
                }
                else { BasicJs.showMessage("未选中记录！"); }


            },
            search: function () {

                var key = "";
                var arrMenu = $("#sMenu").combogrid("getValues").toString().split(",");
                $.each(arrMenu, function (i, item) {
                   if(item.length>0)  key += $.format("'{0}',", item);
                });
                if (key.length > 0) key = key.substring(0, key.length - 1);
                var parm = { sMenu: key };
                var sdate = BasicJs.getDate($("#startDate").val(), "yyyy-MM-dd");
                var edate = BasicJs.getDate($("#endDate").val(), "yyyy-MM-dd");

                if (sdate != null) parm.startDate = sdate;
                if (edate != null) parm.endDate = edate;
                if (sdate != null && edate != null && sdate > edate) {
                    BasicJs.showMessage("开始日期不能大于结束日期！", false);
                    return;
                }
                $('#dg').datagrid('load', parm);


            }

        }

        $(function () {
            //授权
            var funKey = window.name.substring(3);
            BasicJs.authorize("#del", funKey, "DELETE");
            
            //菜单下拉
             $('#sMenu').combogrid({
                 delay: 500,
                 panelWidth: 300,
                 panelHeight: 300,
                 idField: 'FUNCTION_KEY',
                 textField: 'FUNCTION_NAME',
                 url: "../../ashx/System/hMenu.ashx?action=getsub",
                 fit: true,
                 editable: false,
                 multiple: true,
                 pagination: false, //是否分页
                 columns: [[{ field: 'ck', checkbox: true },
                            { field: 'FUNCTION_KEY', title: '', width: 100, hidden: true },
                            { field: 'FUNCTION_NAME', title: '菜单名称', width: 150, sortable: false }
                        ]]
             });

             $('#dg').datagrid(
                     {
                         url: "../../ashx/System/hLoginLog.ashx?action=get",
                         onLoadSuccess: function(data) {
                             $('#dg').datagrid("selectRow", 0);
                         },
                         pageSize : 20,
                         onSelect: function(rowIndex, rowData) {
                             if (rowData) {
                                 var sdate = BasicJs.getDate($("#startDate").val(), "yyyy-MM-dd");
                                 var edate = BasicJs.getDate($("#endDate").val(), "yyyy-MM-dd");
                                 var parm = {};
                                 if (sdate != null) parm.startDate = sdate;
                                 if (edate != null) parm.endDate = edate;
                                 $('#dgDetail').datagrid({
                                     url: "../../ashx/System/hLoginLog.ashx?action=getdetail&funkey=" + rowData.FUNCTION_KEY,
                                     pageSize: 20,
                                     queryParams: parm,
                                     pageNumber: 1
                                 });
                             }
                             else $('#dgDetail').datagrid("loadData", { total: 0, rows: [] });
                         }
                     }
                );

            pageJs.resize($(window).height(), $(window).width());
            pageJs.url = '../../ashx/System/hLoginLog.ashx';
        });  
    </script>
</body>
</html>
